<template>
    <section class="jumbotron">
        <h3 class="jumbotron-heading">Search Github Users</h3>
        <div>
            <input type="text" placeholder="enter the name you search" v-model="username" />&nbsp;
            <button @click="find">Search</button>
        </div>
    </section>
</template>
<script>
    import axios from 'axios'
    export default {
        name: 'Search',
        data() {
            return {
                username: ''
            }
        },
        methods: {
            find() {
                this.$bus.$emit('getusers', { IsFirst: false, IsLoading: true, errormsg: '', user: [] })
                axios.get(`https://api.github.com/search/users?q=${this.username}`).then(
                    resopnse => {
                        console.log('请求成功' + resopnse.data.items);
                        // let userdata = resopnse.data.items;
                        this.$bus.$emit('getusers', { IsFirst: false, IsLoading: false, errormsg: '', user: resopnse.data.items })
                    },
                    error => {
                        console.log('请求错误' + error.message);
                        this.$bus.$emit('getusers', { IsFirst: false, IsLoading: false, errormsg: error.message, user: [] })
                    }
                )
            }
        },

    }
</script>
<style>
</style>